﻿<?xml version="1.0" encoding="utf-8" ?>
<!--namespace必须用否者就报错（读取配置文件报：未将对象引用设置到对象的实例）-->
<sqlMap namespace="" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <statements>

    <insert id="AddBook" parameterClass="hashtable">
      INSERT  dbo.Book (BookID ,BookName,BookAuthor,BookCategoryName,BookCategoryCode,BookPublisherCode,BookPublisherName)
      VALUES  (#BookID# , #BookName#,#BookAuthor#,#BookCategoryName#,#BookCategoryCode#,#BookPublisherCode#,#BookPublisherName#)
    </insert>

    <update id="UpdateBook" parameterClass="hashtable" restltClass="int">
      UPDATE  [Book]
      SET
      [BookCategoryName] =#BookCategoryName#
      ,[BookCategoryCode] = #BookCategoryCode#
      ,[BookName] =#BookName#
      ,[BookAuthor] = #BookAuthor#
      ,[BookPublisherCode] =  #BookPublisherCode#
      ,[BookPublisherName] = #BookPublisherName#
      WHERE BookID=#BookID#

    </update>
    <select id="GetBookList" resultClass="HashTable">
      SELECT   *
      FROM [Book]

      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty prepend="and" property="BookCategoryCode">
            BookCategoryCode =  '$BookCategoryCode$'
          </isNotEmpty>
          <isNotEmpty   property="BookName">
            BookName like '%$BookName$%'
          </isNotEmpty>
          <isNotEmpty   property="BookCategoryName">
            BookCategoryName like '%$BookCategoryName$%'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>

    <insert id="InsertCategory" parameterClass="hashtable" resultClass="int">
      INSERT INTO [Category] (
      [CategoryCode] ,
      [CategoryName] ,
      [CategoryParentName] ,
      [CategoryParentCode] ) VALUES (#CategoryCode#,#CategoryName#,#CategoryParentName#,#CategoryParentCode#)
    </insert>

    <update id="UpdateCategory" parameterClass="hashtable" resultClass="int">
      update [Category] set
      [CategoryCode] = #CategoryCode#
      ,
      [CategoryName] = #CategoryName#
      ,
      [CategoryParentName] = #CategoryParentName#
      ,
      [CategoryParentCode] = #CategoryParentCode#
      where CategoryCode= #CategoryCode#
    </update>

    <delete id="DeleteCategory" parameterClass="string" resultClass="int">
      delete from [Category]
      where  [CategoryCode] = #CategoryCode#
    </delete>
    <delete id="DeleteCategoryList" parameterClass="string" resultClass="int">
      delete from [Category] where CategoryCode in
      <iterate   property="CategoryCodeList" open="(" close=")"  conjunction=",">
        #CategoryCodeList[]#
      </iterate>
    </delete>
    <delete id="DeleteBookList" parameterClass="string" resultClass="int">
      delete from [Book] where BookID in
      <iterate   property="BookCodeList" open="(" close=")"  conjunction=",">
        #BookCodeList[]#
      </iterate>
    </delete>

    <select id="GetCategoryAll" resultClass="HashTable">
      SELECT   *
      FROM [Category]
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty prepend="and" property="CategoryParentCode">
            CategoryParentCode =  '$CategoryParentCode$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>

    <select id="GetCategoryTreeList" resultClass="HashTable">
      SELECT   *
      FROM [Category] where CategoryParentCode= #CategoryParentCode#
    </select>

    <select id="GetPublisherList" resultClass="HashTable">
      SELECT   *
      FROM [Publisher]
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty   property="PublisherName">
            PublisherName like '%$PublisherName$%'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>

    <insert id="InsertPublisher" parameterClass="hashtable" resultClass="int">
      INSERT INTO [Publisher] (
      [PublisherCode] ,
      [PublisherName] ,
      [PublisherUrl] ) VALUES (#PublisherCode#,#PublisherName#,#PublisherUrl#)
    </insert>

    <update id="UpdatePublisher" parameterClass="hashtable" resultClass="int">
      update [Publisher] set
      [PublisherCode] = #PublisherCode#,
      [PublisherName] = #PublisherName#,
      [PublisherUrl] = #PublisherUrl#
      where PublisherCode= #PublisherCode#
    </update>


    <delete id="DeletePublisherList" parameterClass="string" resultClass="int">
      delete from [Publisher] where PublisherCode in
      <iterate   property="PublisherCodeList" open="(" close=")"  conjunction=",">
        #PublisherCodeList[]#
      </iterate>
    </delete>
  </statements>
</sqlMap>